<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <title>新增药品</title>
    <div th:insert="user/common::head"></div>
</head>

<body class="">
<div class="wrapper ">
    <div th:insert="~{user/common::sidebar(active='drug_list.html')}"></div>
    <div class="main-panel">
        <!-- Navbar导航栏 -->
        <nav th:replace="~{user/common::navbar}"></nav>
        <!-- End Navbar -->
        <div class="panel-header panel-header-sm">
        </div>
        <div class="content">
            <div class="row">
                <div class="col-md-8 offset-2">
                    <div class="card">
                        <div class="card-header">
                            <h5 class="title" style="display: inline">新增药品</h5>
                        </div>
                        <div class="card-body">
                            <form id="add_form" method="post">

                                <div class="row pt-5">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>药品ID</label>
                                            <input name="drugId" type="text" class="form-control"  readonly>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>药品名称</label>
                                            <input name="drugName"  type="text" class="form-control" placeholder="药品的名称" >
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>药品价格</label>
                                            <input name="drugPrice"  type="number" class="form-control" placeholder="药品的价格" >
                                        </div>
                                    </div>
                                </div>

                                <div class="row pt-5">
                                    <div class="col-md-12 ">
                                        <div class="form-group">
                                            <label>药品介绍</label>
                                            <textarea name="drugInfo"  rows="5" cols="80" class="form-control" placeholder="请输入药品的具体地址。" style="max-height: 200px"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-8 offset-3">
                                        <a class="btn-warning btn btn-lg col-4 text-white" th:href="@{/toDrugList}">返回</a>
                                        <input type="button" onclick="addDrug()" class="btn-primary btn btn-lg col-4" value="新增">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--底部footer-->
        <footer th:replace="~{user/common::footer}"></footer>
    </div>
</div>


<script>
    function addDrug(){
        var formData = $("#add_form").serialize();
        $.ajax({
            sync:false,
            url:'/drug/add',
            data: formData,
            method:'post',
            dataType:'text',
            success:function(result){
                if(result==='添加成功!'){
                    demo.showNotification('success',result);
                    setTimeout(function (){
                        window.location = '/toDrugList'
                    },1000)
                    return;
                }
                demo.showNotification('danger',result);
            }
        })
    }


</script>

<!--通用footerJs-->
<script th:replace="~{user/common::footerJs}"></script>

</body>
</html>
